#include("/front/teacher/_layout.html")
#@layout()
#define layoutImportcss()
#end
#define layoutHead()
	<title>通知</title>
#end
#define layoutHome()

#include("inc_toolbar.html")

<div class="page-content messages-page-content infinite-scroll-content">
	<div class="banner">
		<img src="/front/img/note2.png" alt="">
		<div style="position: absolute; top:60px; width: 100%; text-align: center; font-size: 28px; color: white; font-weight: bold;"></div>
	</div>

	<ul id="ul_notes">
	</ul>
	<!--加载gif图-->
	<div class="preloader infinite-scroll-preloader"></div>
</div>

#end
#define layoutImportjs()
#end
#define layoutScript()
<script type="text/javascript">
	var cur_pageNo = 1;
	var cur_pageTotals = 1;
	// Loading flag
	var loading = false;
	
	function bindEvent(){
	}
	
	// 监听滚动事件
	$$('.infinite-scroll-content').on('infinite', function () {
	    // Exit, if loading in progress
		if (loading) return;

		if (checkEndPage()){
			return;
		}

		// Set loading flag
		loading = true;
	
	    getPage(cur_pageNo+1);
	});
	
	function checkEndPage(){
		if (cur_pageNo>=cur_pageTotals){
			app.infiniteScroll.destroy('.infinite-scroll-content');
			$$('.infinite-scroll-preloader').html('没有更多数据了！').addClass('loaded').removeClass('preloader').removeClass('infinite-scroll-preloader');
			
			return true;
		}else{
			return false;
		}
	}
	
	function getPage(pageNo){
		var surl = "/front/teacher/notes/getPage?pageNo=" + pageNo + "&pageSize=" + global_pagesize+ "";
		sendPost(surl, null, function(res){
			//console.log(res);
			loading = false;
			
			cur_pageNo = pageNo;
			
			if (pageNo == 1){
				$$('#ul_notes').html('');
			}
			if (res.pageData.list.length>0){
				cur_pageTotals = res.pageData.totalPage;
				var shtml = '';
				for (var i = 0; i < res.pageData.list.length; i++) {
					var jdata = res.pageData.list[i];
					shtml += getTemplateHtml(jdata);
				}
				$$('#ul_notes').append(shtml);
			}
			
			// 绑定事件
			//bindEvent();
			
			checkEndPage();
		});
	}
	
	function getTemplateHtml(jdata){
		//console.log(jdata);
		var stime = '';
		var saddr = '';
		var sicon = 'volume_fill';
		if (jdata.type_id == 2){
			sicon = 'home_fill';
			if (!isBlank(jdata.start_time) && !isBlank(jdata.end_time) && !isBlank(jdata.show_address)){
				stime = '<div class="time">时间：'+formatDate(jdata.start_time, 'M月d日 hh:mm')+'至'+formatDate(jdata.end_time, 'M月d日 hh:mm')+'</div>';
				saddr = '地点：'+formatNullValue(jdata.show_address)+'';
			}
		}
		var shtml = `
					<li class="block block-line-distance messages-block">
						<div class="row">
							<div class="col-15">
								<span class="head-portrait messages-head-icons">
									<i class="f7-icons size-icon28">${sicon}</i>
								</span>
							</div>
							<div class="col-85">
								<div class="block-header"><b>${jdata.note_title}</b></div>
								<div class="block-content">
									<p class="my-sigle-line">${jdata.note_desc}</p>
									${stime}
									<div class="row">
										<div class="col-70 location">${saddr}</div>
										<div class="col-30"><a href="/front/teacher/notes/detaile?id=${jdata.note_id}" class="button button-small external">详情</a></div>
									</div>
								</div>
							</div>
						</div>
					</li>
		`;
		
		return shtml;
	}
	
	getPage(1);
</script>
#end